package ProR;

import java.awt.*;

import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import java.util.Locale;

import javax.swing.*;
import javax.swing.border.TitledBorder;



import com.toedter.calendar.JDateChooser;


public class Employee extends JPanel{
          /**
         * 
         */
      private static final long serialVersionUID = 1L;
      private Font f;
      private JPanel p;
      private JLabel labelHeader,labelSubheader,labelEmployeeCode,labelStartdate,labelName,labelSurname,labelGender,labelHomeNo,labelSoi,labelStreet,labelSubdistrict,labelDistrict,labelProvince,labelZipcode,labelTelNo,labelPic,labelPosition,labelChoose;
      private JTextField textEmployeeCode,textName,textSurname,textHomeNo,textSoi,textStreet,textSubdistrict,textDistrict,textProvince,textZipcode,textTelNo;
      private JComboBox<String> comboGender,comboPosition;
      private JButton buttonFind,buttonSave,buttonDelete,buttonBrowse;
      private JDateChooser calendar;
      int Width = 569, Height= 415;
      String  b = "",picAddress = "";
      
      public Employee(){
          setLayout(null);
          setBorder(BorderFactory.createTitledBorder(null, "Employee", TitledBorder.CENTER, TitledBorder.DEFAULT_POSITION,new Font("Segoe UI",Font.PLAIN,14)));
          setBackground(new Color(238, 238, 238));
          setComponent();
          setBounds(10, 159, 569, 442);
  }
      public void setComponent(){
          p = new JPanel();
          p.setBorder(BorderFactory.createTitledBorder(null, "ที่อยู่", TitledBorder.LEFT, TitledBorder.DEFAULT_POSITION,new Font("Tahoma",Font.PLAIN,12)));
          p. setLayout(null);
          add(p);
          p.setBounds(50,130,290,229);
          p.setVisible(true);
          f = new Font("Tahoma",Font.PLAIN,12);
          
          labelHeader = new JLabel("EMPLOYEE");
          labelHeader.setFont(new Font("Segoe UI",Font.BOLD,18));
          labelSubheader = new JLabel("แสดงรายละเอียดและแก้ไขข้อมูลพนักงาน..");
          labelSubheader.setFont(new Font("Tahoma",Font.PLAIN,11));
          labelEmployeeCode = new JLabel("รหัสพนักงาน:");
          labelEmployeeCode.setFont(f);
          labelStartdate = new JLabel("วันที่เริ่มทำงาน:");
          labelStartdate.setFont(f);
          labelName = new JLabel("ชื่อ:");
          labelName.setFont(f);
          labelSurname = new JLabel("สกุล:");
          labelSurname.setFont(f);
          labelGender = new JLabel("เพศ:");
          labelGender.setFont(f);
          labelHomeNo = new JLabel("บ้านเลขที่:");
          labelHomeNo.setFont(f);
          labelSoi = new JLabel("ซอย:");
          labelSoi.setFont(f);
          labelStreet = new JLabel("ถนน:");
          labelStreet.setFont(f);
          labelSubdistrict = new JLabel("แขวง/ตำบล:");
          labelSubdistrict.setFont(f);
          labelDistrict = new JLabel("เขต/อำเภอ:");
          labelDistrict.setFont(f);
          labelZipcode = new JLabel("รหัสไปรษณีย์:");
          labelZipcode.setFont(f);
          labelProvince = new JLabel("จังหวัด:");
          labelProvince.setFont(f);
          labelTelNo = new JLabel("เบอร์โทรศัพท์:");
          labelTelNo.setFont(f);
          labelPic = new JLabel();
          labelPosition = new JLabel("ตำแหน่ง:");
          labelPosition.setFont(f);
          labelChoose = new JLabel("เลือกรูป:");
          labelChoose.setFont(f);
          
          //set TextField
          
          textEmployeeCode = new JTextField();
          textEmployeeCode.setFont(f);
          textName = new JTextField();
          textName.setFont(f);
          textSurname = new JTextField();
          textSurname.setFont(f);
          textHomeNo = new JTextField();
          textHomeNo.setFont(f);
          textSoi = new JTextField();
          textSoi.setFont(f);
          textStreet = new JTextField();
          textStreet.setFont(f);
          textSubdistrict = new JTextField();
          textSubdistrict.setFont(f);
          textDistrict = new JTextField();
          textDistrict.setFont(f);
          textProvince = new JTextField();
          textProvince.setFont(f);
          textZipcode = new JTextField();
          textZipcode.setFont(f);
          textTelNo = new JTextField();
          textTelNo.setFont(f);
          
          buttonFind = new JButton("ค้นหา");             buttonFind.setFont(f);
          buttonFind.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
          buttonFind.setIcon(new ImageIcon("D:\\Project\\src\\pic\\search.png"));
                
          buttonSave = new JButton("บันทึก");                   buttonSave.setFont(f);
          buttonSave.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
          buttonSave.setIcon(new ImageIcon("D:\\Project\\src\\pic\\save.png"));
                
          buttonDelete = new JButton("ลบ");             buttonDelete.setFont(f); 
          buttonDelete.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
          buttonDelete.setIcon(new ImageIcon("D:\\Project\\src\\pic\\delete.png"));
          
          buttonBrowse = new JButton("Browse..");       buttonBrowse.setFont(f); 
          buttonBrowse.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
              
                  
          calendar = new JDateChooser();
          //String day = ((JTextField)calendar.getDateEditor().getUiComponent()).getText();
          
          String Sex[] = {"ชาย","หญิง"};
          String Position[] = {"เจ้าของร้าน","พนักงาน"};
          comboGender = new JComboBox<String>(Sex);
          comboGender.setFont(f);
          comboGender.setBackground(new Color(238,238,238));
          
          comboPosition = new JComboBox<String>(Position);
          comboPosition.setFont(f);
          comboPosition.setBackground(new Color(238,238,238));
          
          add(labelHeader);
          add(labelSubheader);
          add(labelEmployeeCode);
          add(labelStartdate);
          add(labelName);
          add(labelSurname);
          add(labelGender);
          add(labelTelNo);
          add(labelPic);
          add(labelPosition);
          add(labelChoose);
          p.add(labelHomeNo);
          p.add(labelSoi);
          p.add(labelStreet);
          p.add(labelSubdistrict);
          p.add(labelDistrict);
          p.add(labelZipcode);
          p.add(labelProvince);
          
          add(textEmployeeCode);
          add(textName);
          add(textSurname);
          add(textTelNo);
          p.add(textHomeNo);
          p.add(textSoi);
          p.add(textStreet);
          p.add(textSubdistrict);
          p.add(textDistrict);
          p.add(textZipcode);
          p.add(textProvince);
          
          add(buttonFind);
          add(buttonSave);
          add(buttonDelete);
          add(buttonBrowse);
          
          add(comboGender);
          add(comboPosition);
          
          add(calendar);
          
          
          
  
          //a.setBounds(20, 10, 20, 20); 
          labelHeader.setBounds(20, 20, 150, 20);
          labelSubheader.setBounds(17, 45, 250, 15);
          labelEmployeeCode.setBounds(40, 75, 70, 15);
          labelStartdate.setBounds(240, 75, 85, 15);
          labelName.setBounds(40, 105, 30, 15);
          labelSurname.setBounds(195, 105, 30, 15);
          labelGender.setBounds(355, 105, 30, 15);
          labelHomeNo.setBounds(60, 32, 70, 15);
          labelSoi.setBounds(86, 57, 50, 15);
          labelStreet.setBounds(87, 82, 50, 15);
          labelSubdistrict.setBounds(49, 107, 100, 15);
          labelDistrict.setBounds(54, 132, 100, 15);
          labelProvince.setBounds(74, 157, 70, 15);
          labelZipcode.setBounds(43, 182, 100, 15);
          labelTelNo.setBounds(91, 380, 90, 15);
          
          labelPic.setBounds(390, 160, 150, 150);			labelPic.setHorizontalAlignment(JLabel.CENTER);
          labelPosition.setBounds(370, 330, 90, 15);
          labelChoose.setBounds(370, 360, 90, 15);
  
          textEmployeeCode.setBounds(115,72,120,20);
          textName.setBounds(70, 102, 120, 20);
          textSurname.setBounds(230, 102, 120, 20);
          textHomeNo.setBounds(120,30,120,20);
          textSoi.setBounds(120,55,120,20);
          textStreet.setBounds(120,80,120,20);
          textSubdistrict.setBounds(120,105,120,20);
          textDistrict.setBounds(120,130,120,20);
          textProvince.setBounds(120,155,120,20);
          textZipcode.setBounds(120,180,120,20);
          textTelNo.setBounds(170, 378, 120, 20);
                  
  
          buttonFind.setBounds(460, 40, 85, 24);
          buttonSave.setBounds(460, 70, 85, 24);
          buttonDelete.setBounds(460, 100, 85, 24);
          buttonBrowse.setBounds(430, 360, 85, 24);
                  
          comboGender.setBounds(390, 102, 55, 20);
          comboPosition.setBounds(430, 330, 80, 20);
          
          calendar.setBounds(328, 73, 120, 20);
          calendar.setLocale(new Locale("th", "TH"));
                  
          Setup.setTextFieldNoInputNumber(textName,textSurname,textProvince,textSubdistrict,textDistrict);
          Setup.setTextFieldInputTel(textTelNo);
          Setup.setTextFieldInputNumber(textSoi,textHomeNo);
          
          buttonBrowse.addActionListener(new ActionListener() {
              
              @Override
              public void actionPerformed(ActionEvent arg0) {
                      // TODO Auto-generated method stub
            	  FileDialog f = new FileDialog(new Frame());
                  f.setVisible(true);
                  
                  // if not select picture at first.It will not show.
                  if(f.getDirectory() == null){
                	  if(b.equals(""))
                		  labelPic.setIcon(new ImageIcon(b));
                  }
                  else{
                	  String pic = f.getDirectory()+f.getFile();
                	  picAddress = pic.replace("\\",    "\\\\");
                	  b = picAddress;
                	  labelPic.setIcon(new ImageIcon(picAddress));
                  }
              }
          });
              
          buttonFind.addActionListener(new ActionListener() {
                
                @Override
                public void actionPerformed(ActionEvent arg0) {
                        // TODO Auto-generated method stub
                        EmployeeFind EmpFind = new EmployeeFind();
                        EmpFind.setVisible(true);
                }
          });
                  
      }
}
}
